import request from '@/utils/http'
import { BaseResult } from '@/types/axios'
import { UserInfo } from '@/types/store'
import { LoginData, UserModel } from '@/api/userApi/userModels'

export class UserService {
  // 登录接口
  static login(data: LoginData): Promise<BaseResult> {
    return request.post({
      url: 'users/login',
      data: data
    })
  }

  // 获取用户信息
  static getUserInfo(): Promise<BaseResult<UserInfo>> {
    return request.get({
      url: 'users/info'
    })
  }
  // 注销接口
  static logout(): Promise<BaseResult> {
    return request.post({
      url: 'users/logout'
    })
  }
  // 刷新token
  static refreshToken(refreshToken: string): Promise<BaseResult> {
    return request.post({
      url: 'users/refreshToken',
      data: {
        refreshToken
      }
    })
  }
  // 获取用户列表
  static getUserList(): Promise<BaseResult> {
    return request.get({
      url: 'users/list'
    })
  }
  // 更新用户信息
  static updateUserInfo(data: UserModel): Promise<BaseResult> {
    return request.put({
      url: 'users/update',
      data: data
    })
  }
  // 修改密码
  static updatePassword(data: { oldPassword: string; newPassword: string }): Promise<BaseResult> {
    return request.put({
      url: 'users/password',
      data: data
    })
  }
  // 用户头像上传
  static uploadAvatar(data: FormData): Promise<BaseResult> {
    return request.post({
      url: 'images/upload',
      data: data
    })
  }
}
